package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.dto.ReceiptOrderDTO;
import com.ruoyi.system.vo.ReceiptOrderVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ReceiptOrder;
import com.ruoyi.system.service.IReceiptOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 入库单Controller
 * 
 * @author ruoyi
 * @date 2024-12-12
 */
@RestController
@RequestMapping("/wms/order")
public class ReceiptOrderController extends BaseController
{
    @Autowired
    private IReceiptOrderService receiptOrderService;

    /**
     * 查询入库单列表
     */
    @PreAuthorize("@ss.hasPermi('wms:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReceiptOrder receiptOrder)
    {
        startPage();
        List<ReceiptOrderVo> list = receiptOrderService.selectReceiptOrderList(receiptOrder);
        return getDataTable(list);
    }

    /**
     * 导出入库单列表
     */
//    @PreAuthorize("@ss.hasPermi('wms:order:export')")
//    @Log(title = "入库单", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, ReceiptOrder receiptOrder)
//    {
//        List<ReceiptOrderVo> list = receiptOrderService.selectReceiptOrderList(receiptOrder);
//        ExcelUtil<ReceiptOrder> util = new ExcelUtil<ReceiptOrder>(ReceiptOrder.class);
//        util.exportExcel(response, list, "入库单数据");
//    }

    /**
     * 获取入库单详细信息
     */
    @PreAuthorize("@ss.hasPermi('wms:order:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(receiptOrderService.selectReceiptOrderById(id));
    }

    /**
     * 入库
     */
    @PreAuthorize("@ss.hasPermi('wms:order:list')")
    @PostMapping("/s/receipt")
    public AjaxResult receipt(@RequestBody ReceiptOrderDTO receiptOrder)
    {
        return success(receiptOrderService.ReceiptOrder(receiptOrder));
    }

    /**
     * 新增入库单
     */
    @PreAuthorize("@ss.hasPermi('wms:order:add')")
    @Log(title = "入库单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReceiptOrder receiptOrder)
    {
        return toAjax(receiptOrderService.insertReceiptOrder(receiptOrder));
    }

    /**
     * 修改入库单
     */
    @PreAuthorize("@ss.hasPermi('wms:order:edit')")
    @Log(title = "入库单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReceiptOrder receiptOrder)
    {
        return toAjax(receiptOrderService.updateReceiptOrder(receiptOrder));
    }

    /**
     * 删除入库单
     */
    @PreAuthorize("@ss.hasPermi('wms:order:remove')")
    @Log(title = "入库单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(receiptOrderService.deleteReceiptOrderByIds(ids));
    }

    /**
     * 看板数据统计查询
     */
    @PreAuthorize("@ss.hasPermi('wms:order:query')")
    @GetMapping(value = "/s/{status}")
    public AjaxResult selectStatus(@PathVariable("status") int status)
    {
        return success(receiptOrderService.selectStatus(status));
    }

    /**
     * 看板趋势统计查询
     */
    @PreAuthorize("@ss.hasPermi('wms:order:query')")
    @GetMapping(value = "/d/{date1}/{date2}")
    public AjaxResult selectDate(@PathVariable("date1") String date1,@PathVariable("date2") String date2)
    {
        return success(receiptOrderService.selectDate(date1,date2));
    }
}
